package com.jc.cloud.sign.controller.tencent;

import com.tencent.xinge.XingeApp;
import com.tencent.xinge.bean.AudienceType;
import com.tencent.xinge.bean.Message;
import com.tencent.xinge.bean.MessageAndroid;
import com.tencent.xinge.bean.MessageType;
import com.tencent.xinge.push.app.PushAppRequest;
import io.swagger.annotations.Api;
import org.json.JSONObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

/**
 * @BelongsPackage: com.jc.cloud.sign.controller.tencent
 * @Author: whx
 * @CreateTime: 2023-11-10 16:06
 * @Description: TODO
 */

@RestController("/tencent/xingeapp")
@Api("服务接口SDK")
public class XingeAppController {

    @GetMapping("/test")
    public JSONObject test(){
        XingeApp xingeApp = new XingeApp.Builder()
                .appId("1500038578")
                .secretKey("8f180308f72a56d3705d0e2e728fbb23")
                .domainUrl("https://api.tpns.tencent.com/"
                )
                .build();

        //完善PushAppRequest  消息
        PushAppRequest pushAppRequest = new PushAppRequest();

        pushAppRequest.setAudience_type(AudienceType.token);
        pushAppRequest.setMessage_type(MessageType.notify);
        Message message = new Message();
        message.setTitle("title");
        message.setContent("content");
        pushAppRequest.setMessage(message);
        MessageAndroid messageAndroid = new MessageAndroid();
        message.setAndroid(messageAndroid);
        ArrayList<String> tokenList = new ArrayList();
        tokenList.add("04cac74a714f61bf089********63d880993");
        pushAppRequest.setToken_list(tokenList);

        JSONObject ret =  xingeApp.pushApp(pushAppRequest );

        return ret;
    }


}
